/**
 * Created by lixiangcheng on 2017/6/15.
 */

/**login
 *
 */
function register() {
    window.location.href = "../driver/sign/sign.html"
}
function forgotPassword(sourceFrom) {
    //sourceFrom:10-客户，20-司机
    window.location.href = "../login_forgot/forgot.html?sourceFrom=" + sourceFrom
}
//登陆
function loginForm() {
    var logonNam = $('#driverLoginForm').find("#logonNam").val();
    var password = $('#driverLoginForm').find("#password").val();
    if (logonNam == null || logonNam == '') {
        alert('用户名不能为空');
        return false;
    }
    if (password == null || password == '') {
        alert('密码不能为空');
        return false;
    }
    var url = _global.serverHost + "/driver/loginValide.htm";
    var data = $('#driverLoginForm').serialize();
    _callAjaxRequest(url, data, loginBack);
}
//登陆后操作
function loginBack(data) {
    if (data.outResult == "1") {
        setCookie("driverUuid", data.driverUuid);
        try{
        	delegate.setCookie("driverUuid", data.driverUuid);
        	delegate.setCookie("phoneNumber", $('#driverLoginForm').find("#logonNam").val());
      	}catch(e){}
        window.location.href = "../driver/index.html";
    } else if(data.outResult == "2"){
        alert(data.outResultReason);

        window.location.href = "../driver/sign/edit_track.html?driverUserId="+data.driverUserId;
        
    } else{
        alert(data.outResultReason);
    }
    
}
///////


function setCookie(name, value) {
    localStorage.setItem(name, value);
}
function getCookie(name) {
    var nameValue = localStorage.getItem(name);
    if (nameValue == undefined) {
        nameValue = null;
        //window.location.href = "../driver/login.html";
    }
    return nameValue;
}

function delCookie(name) {
    localStorage.removeItem(name);
}


function checkDriverToken(){
    var driverUuid=getCookie("driverUuid");
    if(driverUuid==undefined || driverUuid==null || driverUuid==''){
        window.location.href='../'+_global.driverLoginUrl;
    }else{
        $.ajax({
            type: 'POST',
            url: _global.serverHost + '/driver/validToken.htm',
            dataType: "json",
            data: { 'driverUuid': driverUuid},
            success: function (data) {
                if (data.outResult == '1') {
                    return '1';
                } else {
                    window.location.href='../'+_global.driverLoginUrl;
                }
            }
        });
    }
}

function checkDriverTokenIndex(){
    var driverUuid=getCookie("driverUuid");
    if(driverUuid==undefined || driverUuid==null || driverUuid==''){
        window.location.href=_global.driverLoginUrl;
    }else{
        $.ajax({
            type: 'POST',
            url: _global.serverHost + '/driver/validToken.htm',
            dataType: "json",
            data: { 'driverUuid': driverUuid},
            success: function (data) {
                if (data.outResult == '1') {
                	//alert("==checkDriverTokenIndex=="+JSON.stringify(data));
                	localStorage.setItem("driverInfo", JSON.stringify(data));//保存司机信息
                    return '1';
                } else {
                    window.location.href= _global.driverLoginUrl;
                }
            }
        });
    }
}

/**
 * 清空订单cookie
 */
function clearOrderCookie(){
	var tmpValue='';
	setCookie('vehiclePriceId',tmpValue);
	
	setCookie('bookDate',tmpValue);
	
	setCookie('consignDesc',tmpValue);
	
	setCookie('callType',tmpValue);
	
	setCookie('addrType',tmpValue);
	
	setCookie('waybillRquirement10',tmpValue);
	
	setCookie('waybillRquirement20',tmpValue);
	
	setCookie('waybillRquirement30',tmpValue);
	
	setCookie('startDistrictCode',tmpValue);
	
	setCookie('startAddr',tmpValue);
	setCookie('startPCD',tmpValue);
	
	setCookie('startLocation',tmpValue);
	
	setCookie('endDistrictCode',tmpValue);
	
	setCookie('endAddr',tmpValue);
	
	setCookie('endPCD',tmpValue);
	setCookie('endLocation',tmpValue);
	setCookie('vehiclePriceId',tmpValue);
	setCookie('endDistrictCode1',tmpValue);
	setCookie('endAddr1',tmpValue);
	setCookie('endPCD1',tmpValue);
	setCookie('endLocation1',tmpValue);
	setCookie('endDistrictCode2',tmpValue);
	setCookie('endAddr2',tmpValue);
	
	setCookie('endLocation2',tmpValue);
	setCookie('endPCD2',tmpValue);
	setCookie('goodsRemark',tmpValue);
	setCookie('goodsType',tmpValue);
	setCookie('goodsTypeName',tmpValue);
	setCookie('consignNum',tmpValue);
	setCookie('endAddrCount',tmpValue);
	
	setCookie('startStreet',tmpValue);
	setCookie('startCross',tmpValue);
	setCookie('startDoorNo',tmpValue);
	setCookie('consignMobile',tmpValue);
	setCookie('consignName',tmpValue);
	
	setCookie('endStreet',tmpValue);
	setCookie('endCross',tmpValue);
	setCookie('endDoorNo',tmpValue);
	setCookie('acceptPersonMobile',tmpValue);
	setCookie('acceptPersonName',tmpValue);
	
	setCookie('endStreet1',tmpValue);
	setCookie('endCross1',tmpValue);
	setCookie('endDoorNo1',tmpValue);
	setCookie('acceptPersonMobile1',tmpValue);
	setCookie('acceptPersonName1',tmpValue);
	
	setCookie('endStreet2',tmpValue);
	setCookie('endCross2',tmpValue);
	setCookie('endDoorNo2',tmpValue);
	setCookie('acceptPersonMobile2',tmpValue);
	setCookie('acceptPersonName2',tmpValue);
	
	setCookie('planLoadTime',tmpValue);
	setCookie('planUnloadTime',tmpValue);
	setCookie('planLoadFee',tmpValue);
	setCookie('planUnloadFee',tmpValue);
	setCookie('planLowSpeedTime',tmpValue);
	setCookie('planLowSpeedFee',tmpValue);
}

/**
 * cookie信息给订单
 */
function cookie2Order(){
	var tmpValue=getCookie("vehiclePriceId");
	$("#vehiclePriceId").val(tmpValue);
	var tmpValue=getCookie("bookDate");
	$("#bookDate").val(tmpValue);
	var tmpValue=getCookie("consignDesc");
	$("#consignDesc").val(tmpValue);
	var tmpValue=getCookie("callType");
	$("#callType").val(tmpValue);
	var tmpValue=getCookie("addrType");
	$("#addrType").val(tmpValue);
	var tmpValue=getCookie("waybillRquirement10");
	$("#waybillRquirement10").val(tmpValue);
	var tmpValue=getCookie("waybillRquirement20");
	$("#waybillRquirement20").val(tmpValue);
	var tmpValue=getCookie("waybillRquirement30");
	$("#waybillRquirement30").val(tmpValue);
	var tmpValue=getCookie("startDistrictCode");
	$("#startDistrictCode").val(tmpValue);
	var tmpValue=getCookie("startAddr");
	$("#startAddr").val(tmpValue);
	var tmpValue=getCookie("startPCD");
	$("#startPCD").val(tmpValue);
	var tmpValue=getCookie("startLocation");
	$("#startLocation").val(tmpValue);
	var tmpValue=getCookie("endDistrictCode");
	$("#endDistrictCode").val(tmpValue);
	var tmpValue=getCookie("endAddr");
	$("#endAddr").val(tmpValue);
	var tmpValue=getCookie("endPCD");
	$("#endPCD").val(tmpValue);
	var tmpValue=getCookie("endLocation");
	$("#endLocation").val(tmpValue);
	var tmpValue=getCookie("endDistrictCode1");
	$("#endDistrictCode1").val(tmpValue);
	var tmpValue=getCookie("endAddr1");
	$("#endAddr1").val(tmpValue);
	var tmpValue=getCookie("endPCD1");
	$("#endPCD1").val(tmpValue);
	var tmpValue=getCookie("endLocation1");
	$("#endLocation1").val(tmpValue);
	var tmpValue=getCookie("endDistrictCode2");
	$("#endDistrictCode2").val(tmpValue);
	var tmpValue=getCookie("endAddr2");
	$("#endAddr2").val(tmpValue);
	var tmpValue=getCookie("endPCD2");
	$("#endPCD2").val(tmpValue);
	var tmpValue=getCookie("endLocation2");
	$("#endLocation2").val(tmpValue);
	var tmpValue=getCookie("goodsRemark");
	$("#goodsRemark").val(tmpValue);
	var tmpValue=getCookie("goodsType");
	$("#goodsType").val(tmpValue);
	var tmpValue=getCookie("goodsTypeName");
	$("#goodsTypeName").val(tmpValue);
	var tmpValue=getCookie("consignNum");
	$("#consignNum").val(tmpValue);
	var tmpValue=getCookie("endAddrCount");
	$("#endAddrCount").val(tmpValue);
	 tmpValue=getCookie("customerUuid");
	$("#customerUuid").val(tmpValue);
	
	 tmpValue=getCookie("startStreet");
	$("#startStreet").val(tmpValue);
	tmpValue=getCookie("startCross");
	$("#startCross").val(tmpValue);
	tmpValue=getCookie("startDoorNo");
	$("#startDoorNo").val(tmpValue);
	tmpValue=getCookie("consignMobile");
	$("#consignMobile").val(tmpValue);
	tmpValue=getCookie("consignName");
	$("#consignName").val(tmpValue);
	
	tmpValue=getCookie("endStreet");
	$("#endStreet").val(tmpValue);
	tmpValue=getCookie("endCross");
	$("#endCross").val(tmpValue);
	tmpValue=getCookie("endDoorNo");
	$("#endDoorNo").val(tmpValue);
	tmpValue=getCookie("acceptPersonMobile");
	$("#acceptPersonMobile").val(tmpValue);
	tmpValue=getCookie("acceptPersonName");
	$("#acceptPersonName").val(tmpValue);
	
	tmpValue=getCookie("endStreet1");
	$("#endStreet1").val(tmpValue);
	tmpValue=getCookie("endCross1");
	$("#endCross1").val(tmpValue);
	tmpValue=getCookie("endDoorNo1");
	$("#endDoorNo1").val(tmpValue);
	tmpValue=getCookie("acceptPersonMobile1");
	$("#acceptPersonMobile1").val(tmpValue);
	tmpValue=getCookie("acceptPersonName1");
	$("#acceptPersonName1").val(tmpValue);
	
	tmpValue=getCookie("endStreet2");
	$("#endStreet2").val(tmpValue);
	tmpValue=getCookie("endCross2");
	$("#endCross2").val(tmpValue);
	tmpValue=getCookie("endDoorNo2");
	$("#endDoorNo2").val(tmpValue);
	tmpValue=getCookie("acceptPersonMobile2");
	$("#acceptPersonMobile2").val(tmpValue);
	tmpValue=getCookie("acceptPersonName2");
	$("#acceptPersonName2").val(tmpValue);
	
	tmpValue=getCookie("planLoadTime");
	$("#planLoadTime").val(tmpValue);
	tmpValue=getCookie("planUnloadTime");
	$("#planUnloadTime").val(tmpValue);
	tmpValue=getCookie("planLoadFee");
	$("#planLoadFee").val(tmpValue);
	tmpValue=getCookie("planUnloadFee");
	$("#planUnloadFee").val(tmpValue);
	tmpValue=getCookie("planLowSpeedTime");
	$("#planLowSpeedTime").val(tmpValue);
	tmpValue=getCookie("planLowSpeedFee");
	$("#planLowSpeedFee").val(tmpValue);
	
}
function order2Cookie(){
	var tmpValue=document.getElementsByName("vehiclePriceId")[0].value;
	setCookie('vehiclePriceId',tmpValue);
	
	tmpValue=document.getElementsByName("bookDate")[0].value;
	setCookie('bookDate',tmpValue);
	
	tmpValue=document.getElementsByName("consignDesc")[0].value;
	setCookie('consignDesc',tmpValue);
	
	tmpValue=document.getElementsByName("callType")[0].value;
	setCookie('callType',tmpValue);
	
	tmpValue=document.getElementsByName("addrType")[0].value;
	setCookie('addrType',tmpValue);
	
	tmpValue=document.getElementsByName("waybillRquirement10")[0].value;
	setCookie('waybillRquirement10',tmpValue);
	
	tmpValue=document.getElementsByName("waybillRquirement20")[0].value;
	setCookie('waybillRquirement20',tmpValue);
	
	tmpValue=document.getElementsByName("waybillRquirement30")[0].value;
	setCookie('waybillRquirement30',tmpValue);
	
	
	
	tmpValue=document.getElementsByName("startDistrictCode")[0].value;
	setCookie('startDistrictCode',tmpValue);
	
	//tmpValue=document.getElementsByName("startAddr")[0].value;
	tmpValue=$("#startAddr").val();
	setCookie('startAddr',tmpValue);
	tmpValue=document.getElementsByName("startPCD")[0].value;
	setCookie('startPCD',tmpValue);
	
	tmpValue=document.getElementsByName("startLocation")[0].value;
	setCookie('startLocation',tmpValue);
	
	tmpValue=document.getElementsByName("endDistrictCode")[0].value;
	setCookie('endDistrictCode',tmpValue);
	
	tmpValue=document.getElementsByName("endAddr")[0].value;
	setCookie('endAddr',tmpValue);
	
	tmpValue=document.getElementsByName("endPCD")[0].value;
	setCookie('endPCD',tmpValue);
	tmpValue=document.getElementsByName("endLocation")[0].value;
	setCookie('endLocation',tmpValue);
	tmpValue=document.getElementsByName("vehiclePriceId")[0].value;
	setCookie('vehiclePriceId',tmpValue);
	tmpValue=document.getElementsByName("endDistrictCode1")[0].value;
	setCookie('endDistrictCode1',tmpValue);
	tmpValue=document.getElementsByName("endAddr1")[0].value;
	setCookie('endAddr1',tmpValue);
	tmpValue=document.getElementsByName("endPCD1")[0].value;
	setCookie('endPCD1',tmpValue);
	tmpValue=document.getElementsByName("endLocation1")[0].value;
	setCookie('endLocation1',tmpValue);
	tmpValue=document.getElementsByName("endDistrictCode2")[0].value;
	setCookie('endDistrictCode2',tmpValue);
	tmpValue=document.getElementsByName("endAddr2")[0].value;
	setCookie('endAddr2',tmpValue);
	
	tmpValue=document.getElementsByName("endLocation2")[0].value;
	setCookie('endLocation2',tmpValue);
	tmpValue=document.getElementsByName("endPCD2")[0].value;
	setCookie('endPCD2',tmpValue);
	tmpValue=document.getElementsByName("goodsRemark")[0].value;
	setCookie('goodsRemark',tmpValue);
	tmpValue=document.getElementsByName("goodsType")[0].value;
	setCookie('goodsType',tmpValue);
	tmpValue=document.getElementsByName("goodsTypeName")[0].value;
	setCookie('goodsTypeName',tmpValue);
	tmpValue=document.getElementsByName("consignNum")[0].value;
	setCookie('consignNum',tmpValue);
	tmpValue=document.getElementsByName("endAddrCount")[0].value;
	setCookie('endAddrCount',tmpValue);
	tmpValue=document.getElementsByName("startStreet")[0].value;
	setCookie('startStreet',tmpValue);
	tmpValue=document.getElementsByName("startCross")[0].value;
	setCookie('startCross',tmpValue);
	tmpValue=document.getElementsByName("startDoorNo")[0].value;
	setCookie('startDoorNo',tmpValue);
	tmpValue=document.getElementsByName("consignMobile")[0].value;
	setCookie('consignMobile',tmpValue);
	tmpValue=document.getElementsByName("consignName")[0].value;
	setCookie('consignName',tmpValue);
	
	tmpValue=document.getElementsByName("endStreet")[0].value;
	setCookie('endStreet',tmpValue);
	tmpValue=document.getElementsByName("endCross")[0].value;
	setCookie('endCross',tmpValue);
	tmpValue=document.getElementsByName("endDoorNo")[0].value;
	setCookie('endDoorNo',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonMobile")[0].value;
	setCookie('acceptPersonMobile',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonName")[0].value;
	setCookie('acceptPersonName',tmpValue);
	
	tmpValue=document.getElementsByName("endStreet1")[0].value;
	setCookie('endStreet1',tmpValue);
	tmpValue=document.getElementsByName("endCross1")[0].value;
	setCookie('endCross1',tmpValue);
	tmpValue=document.getElementsByName("endDoorNo1")[0].value;
	setCookie('endDoorNo1',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonMobile1")[0].value;
	setCookie('acceptPersonMobile1',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonName1")[0].value;
	setCookie('acceptPersonName1',tmpValue);
	
	tmpValue=document.getElementsByName("endStreet2")[0].value;
	setCookie('endStreet2',tmpValue);
	tmpValue=document.getElementsByName("endCross2")[0].value;
	setCookie('endCross2',tmpValue);
	tmpValue=document.getElementsByName("endDoorNo2")[0].value;
	setCookie('endDoorNo2',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonMobile2")[0].value;
	setCookie('acceptPersonMobile2',tmpValue);
	tmpValue=document.getElementsByName("acceptPersonName2")[0].value;
	setCookie('acceptPersonName2',tmpValue);
	
	tmpValue=document.getElementsByName("planLoadTime")[0].value;
	setCookie('planLoadTime',tmpValue);
	tmpValue=document.getElementsByName("planUnloadTime")[0].value;
	setCookie('planUnloadTime',tmpValue);
	tmpValue=document.getElementsByName("planLoadFee")[0].value;
	setCookie('planLoadFee',tmpValue);
	tmpValue=document.getElementsByName("planUnloadFee")[0].value;
	setCookie('planUnloadFee',tmpValue);
	tmpValue=document.getElementsByName("planLowSpeedTime")[0].value;
	setCookie('planLowSpeedTime',tmpValue);
	tmpValue=document.getElementsByName("planLowSpeedFee")[0].value;
	setCookie('planLowSpeedFee',tmpValue);
	
}